<?php
namespace api\modules\v1\controllers;
use yii;
use yii\filters\Cors;
use yii\helpers\ArrayHelper;
use yii\rest\ActiveController;
use yii\data\ActiveDataProvider;
/**
 * Country Controller API
 *
 * @author Budi Irawan <deerawan@gmail.com>
 */
class ZhengheController extends  ActiveController
{
    public $modelClass = 'api\modules\v1\models\zhenghe';

    public function behaviors()
    {
        return ArrayHelper::merge(
            [['class' => Cors::className(),],], parent::behaviors());
    }

    public function  init(){
        parent::init();
//        echo 'hello this is ';
    }
    public function actions()
    {
        $actions = parent::actions();
        // 注销系统自带的实现方法

        unset($actions['index'], $actions['update'],  $actions['delete'], $actions['view']);

        return $actions;
    }
    public function actionIndex()
    {
        $request = Yii::$app->request;
        // 返回所有参数
        $token = $request->get('token') ;
        if($token=='123'){
            $modelClass = $this->modelClass;
            $query = $modelClass::find();
            return new ActiveDataProvider([
                'query' => $query
            ]);
        }else if(1){
            $model = new $this->modelClass();
            $model->attributes = Yii::$app->request->get();
//            var_dump($model);
            if (!$model->save()){
                return '服务器开小差了';
            }else{
                return '成功';
            }

        }
        else{
            return null;
        }

    }

}